<template>
	<view class="content">
		<view class="orderTimeBox">
			<view class="titleBox">
				<view class="line1">
				</view>
				<text class="title">场地预约</text>
				<view class="notBlock">
				</view>
				<text class="notLabel">不可预约</text>
				<view class="canBox">
					<view class="canBlock">
					</view>
					<text class="canLabel">已选择</text>
				</view>
			</view>
			<view class="dateBox">
				<text class="month">{{monthValue}}</text>
				<view class="triangle">
				</view>
				<view class="line">
				</view>
				<scroll-view class="dateScrollBox" scroll-x="true" :scroll-into-view="dateId">
					<view class="dateItem" :class="dateIndex==index?'dateActive':''" :id="`item-${index}`"
						v-for="(item,index) in dateArr" :key="index" @click="selDate(index)">
						{{item}}
					</view>
				</scroll-view>
				<uni-section class="selecteMonth">
					<uni-data-select v-mode="monthValue" :localdata="month" @change="changeMonth()" />
					</uni-data-select>
				</uni-section>
			</view>
			<view class="timeContainer">
				<view class="timeBox">
					<text class="timeLabel">开始时间</text>
					<text class="time">{{startTimeValue}}</text>
					<text class="timeArrow">></text>
					<uni-section class="selectetime">
						<uni-data-select v-mode="startTimeValue" :localdata="timeArr" @change="changeStartTime" />
						</uni-data-select>
					</uni-section>
				</view>
				<view class="timeBox">
					<text class="timeLabel">结束时间</text>
					<text class="time">{{endTimeValue}}</text>
					<text class="timeArrow">></text>
					<uni-section class="selectetime">
						<uni-data-select v-mode="endTimeValue" :localdata="timeArr" @change="changeEndTime" />
						</uni-data-select>
					</uni-section>
				</view>
			</view>
		</view>
		<view class="orderInfoBox">
			<view class="item" style="align-items: center;">
				<view class="line1" style="margin-left: -40rpx;"></view>
				<text class="left">人数：</text>
				<input type="text" v-model="num" class="right" placeholder="请输入人数" />
			</view>
			<view class="item">
				<text class="left">特殊需求：</text>
				<input type="text" v-model="demand" class="right" placeholder="请输入特殊需求" />
			</view>
			<view class="item">
				<text class="left">使用目的：</text>
				<input type="text" v-model="purpose" class="right" placeholder="请输入使用目的" />
			</view>
			<view class="item" style="flex-direction: column;">
				<text class="left">具体用途：</text>
				<textarea v-model="notes" placeholder="请输入您的具体用途" class="note" />
			</view>
		</view>
		<view class="orderInfoBox">
			<view class="item" style="align-items: center;">
				<view class="line1" style="margin-left: -40rpx;"></view>
				<text class="left" style="font-size: 28rpx;">个人信息：</text>
			</view>
			<view class="item">
				<text class="left">姓 名：</text>
				<input type="text" v-model="name" class="right" placeholder="请输入姓名" />
			</view>
			<view class="item">
				<text class="left">房间号：</text>
				<input type="text" v-model="fanghao" class="right" placeholder="请输入房间号" />
			</view>
			<view class="item">
				<text class="left">联系方式：</text>
				<input type="text" v-model="tel" class="right" placeholder="请输入联系方式" maxlength="11"/>
			</view>
		</view>
		<view class="cartBox">
			<text class="totalLabel">合计：</text>
			<text class="totalPrice">￥{{info.data.price}}</text>
			<view class="submit" @click="submit">
				确认预约
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				month: [],
				monthValue: '',
				value: 0,
				data: '',
				plate: '',
				timeArr: [], //可预约时段
				timeIndex: -1,
				time: '',
				service_data: '',
				dateArr: [],
				dateIndex: -1,
				date: '',
				yearArr: [],
				nextMonth: 0,
				dateId: '',
				timeId: '',
				startTimeValue: '请选择',
				endTimeValue: '请选择',
				timeArr: [],
				demand: '',
				purpose: '',
				notes: '',
				name: '',
				tel: '',
				fanghao: '',
				num: '',
				info: ''
			}
		},
		onLoad() {
			this.info = this.$store.state.tempData;
			this.$store.commit('clearTempData');
			this.dateArr = this.$getDateRanges().currentMonthDates //赋值当前月份剩余日期
			this.yearArr[0] = this.$getCurrentAndNextMonthYear().currentMonthYear;
			this.yearArr[1] = this.$getCurrentAndNextMonthYear().nextMonthYear;
			this.month = this.$getFormattedMonths();
			this.monthValue = this.month[0].text;
			this.service_data = this.yearArr[0] + '-' + this.dateArr[0].toString()
				.padStart(2, '0');
			this.getTime()
		},
		methods: {
			submit() {
				if (!this.date) {
					return this.$toast('请选择日期');
				}
				if (!this.startTimeValue || this.startTimeValue == "请选择") {
					return this.$toast("请选择开始时间");
				}
				if (!this.endTimeValue || this.endTimeValue == "请选择") {
					return this.$toast("请选择结束时间");
				}
				const start = new Date(`1970-01-01T${this.startTimeValue}:00`);
				const end = new Date(`1970-01-01T${this.endTimeValue}:00`);
				if (end <= start) {
					return this.$toast("结束时间必须大于开始时间");
				}
				if (!this.num) {
					return this.$toast("请输入人数");
				}
				// if (!this.demand) {
				// 	return this.$toast("请输入特殊需求");
				// }
				if (!this.purpose) {
					return this.$toast("请输入使用目的");
				}
				if (!this.notes) {
					return this.$toast("请输入您具体用途");
				}
				if (!this.name) {
					return this.$toast("请输入您的姓名");
				}
				if (!this.fanghao) {
					return this.$toast("请输入房间号");
				}
				if (!this.tel || !(/^1[3|4|5|6|8|7|9][0-9]\d{8}$/.test(this.tel))) {
					return this.$toast('请输入正确的联系方式');
				}
				this.$store.commit('setTempData', this.$data);
				this.$navto.navto("/pages/juanjiahui_place_order/juanjiahui_place_order")
			},
			getTime() {
				this.$request.post(`sub_time_list`, {
					type: 2,
					service_data: this.service_data,
					sub_type: 2
				}).then(res => {
					this.timeArr = res.data.data.filter(item => item.status === true).map((item, index) => ({
						value: index,
						text: item.time_frame
					}));
				})
			},
			// 选择日期
			selDate(index, status) {
				this.dateIndex = index;
				this.date = this.dateArr[index];
				this.dateArr = this.$getDateRanges().currentMonthDates;
				if (this.nextMonth == 0) {
					this.service_data = this.yearArr[0] + '-' + this.date.toString().padStart(2, '0');
				} else {
					this.service_data = this.yearArr[1] + '-' + this.date.toString().padStart(2, '0');
				}
				this.getTime();
			},
			// 选择月份
			changeMonth(e) {
				this.timeIndex = -1;
				this.dateIndex = -1;
				if (e == 0) { //当前月份
					this.nextMonth = 0;
					console.log(this.$getCurrentAndNextMonthYear().currentMonthYear);
					this.dateArr = this.$getDateRanges().currentMonthDates;
					this.service_data = this.yearArr[0] + '-' + this.dateArr[0].toString().padStart(2, '0');
				} else { //下个月
					this.nextMonth = 1;
					console.log(this.$getCurrentAndNextMonthYear().nextMonthYear);
					this.dateArr = this.$getDateRanges().nextMonthDates;
					this.service_data = this.yearArr[1] + '-' + this.dateArr[0].toString().padStart(2, '0');
				}
				console.log(this.nextMonth)
				this.monthValue = this.month[e].text;
				this.getTime();
				this.dateId = 'item-0';
				setTimeout(() => {
					this.dateId = '';
				}, 1000)
			},
			changeEndTime(e) {
				console.log("e:", e);
				this.endTimeValue = this.timeArr[e].text;
			},
			changeStartTime(e) {
				console.log("e:", e);
				this.startTimeValue = this.timeArr[e].text;
			},
		}
	}
</script>
<style lang="scss" scoped>
	.cartBox {
		position: fixed;
		z-index: 3;
		bottom: 0;
		width: 100%;
		height: 130rpx;
		background-color: #ffffff;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		padding-left: 40rpx;
		padding-right: 40rpx;
		justify-content: space-between;
		padding-bottom: 20rpx;
		border-top: 1rpx solid #f0f0f0;

		.totalPrice {
			color: #121212;
			font-weight: 700;
			font-size: 34rpx;
			letter-spacing: 2rpx;
		}

		.totalLabel {
			font-weight: 700;
			font-size: 20rpx;
			color: #121212;
		}

		.submit {
			width: 420rpx;
			height: 80rpx;
			border-radius: 40rpx;
			background: #121212;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: 700;
			font-size: 28rpx;
			color: #FFFFFF;
			letter-spacing: 5rpx;
			margin-left: auto;
		}
	}

	.orderInfoBox {
		// padding: 0rpx 40rpx 0rpx 40rpx;
		box-sizing: border-box;
		background-color: #fff;
		border-top: 25rpx solid #f0f0f0;

		.item {
			width: 670rpx;
			position: relative;
			padding-top: 45rpx;
			padding-bottom: 45rpx;
			border-bottom: 1rpx solid #121212;
			display: flex;
			justify-content: space-between;
			font-size: 26rpx;
			margin-left: 40rpx;

			.note {
				width: 100%;
				height: 200rpx;
				margin-top: 20rpx;
			}

			.right {
				font-weight: 500;
				font-size: 26rpx;
				color: #121212;
				display: flex;
				margin-left: auto;
				text-align: right;
				align-items: center;
			}

			.left {
				font-weight: 700;
				font-size: 26rpx;
				color: #121212;
			}
		}

		.item:last-child {
			border: none;
		}
	}

	.timeBox {
		padding: 30rpx 0rpx 30rpx 0rpx;
		display: flex;
		justify-content: space-between;
		width: 670rpx;
		box-sizing: border-box;
		position: relative;

		.time {
			font-weight: 700;
			font-size: 26rpx;
			color: #121212;
			margin-right: 40rpx;
		}

		.timeLabel {
			font-weight: 700;
			font-size: 26rpx;
			color: #121212;
			letter-spacing: 5rpx;
		}


		.timeArrow {
			position: absolute;
			right: 0rpx;
			font-size: 24rpx;
			// top: 50rpx;
			color: #8E8E8E;
		}

	}

	.timeContainer {
		width: 100%;
		background-color: #fff;
	}





	.orderTimeBox {
		// width: 750rpx;
		background: #ffffff;
		padding: 60rpx 40rpx 0rpx 40rpx;
		// border-top: 25rpx solid #f0f0f0;
		border-top: 25rpx solid #f0f0f0;

		.dateBox {
			position: relative;
			width: 670rpx;
			display: flex;
			align-items: center;
			padding-top: 58rpx;
			padding-bottom: 58rpx;
			border-bottom: 1rpx solid #121212;

			.selecteMonth {
				position: absolute;
				left: 0rpx;
				width: 120rpx;
				height: 50%;
			}

			.dateScrollBox {
				// width: 450rpx;
				margin-left: 54rpx;
				display: flex;
				white-space: nowrap;
				overflow-x: scroll;

				.dateItem {
					width: 80rpx;
					height: 80rpx;
					border: 1rpx solid #121212;
					border-radius: 50%;
					// display: flex;
					display: inline-flex;
					font-weight: 500;
					font-size: 26rpx;
					color: #121212;
					align-items: center;
					justify-content: center;
					margin-right: 33rpx;
					flex: 0 0 auto;
					box-sizing: border-box;
				}

				.dateActive {
					background: #FF6E5D;
					// border: none;
					color: #ffffff;
					border: 1rpx solid #FF6E5D;
				}

				.dateDisable {
					background: #f0f0f0;
					border: none;
				}
			}

			.line {
				width: 1rpx;
				height: 44rpx;
				background: #c7c7c7;
				margin-left: 50rpx;
			}

			.triangle {
				width: 24rpx;
				height: 18rpx;
				background: #121212;
				clip-path: polygon(0 0, 100% 50%, 0 100%);
			}

			.month {
				width: 150rpx;
				text-align: center;
				font-weight: 700;
				font-size: 30rpx;
				color: #121212;
				white-space: nowrap;
			}
		}

		.line {
			width: 1rpx;
			height: 44rpx;
			background: #c7c7c7;
			margin-left: 50rpx;
		}

		.triangle {
			width: 24rpx;
			height: 18rpx;
			background: #121212;
			clip-path: polygon(0 0, 100% 50%, 0 100%);
		}

		.month {
			width: 150rpx;
			text-align: center;
			font-weight: 700;
			font-size: 30rpx;
			color: #121212;
			white-space: nowrap;
		}
	}

	.titleBox {
		width: 670rpx;
		display: flex;
		align-items: center;
		padding-bottom: 53rpx;
		border-bottom: 1rpx solid #121212;



		.timeIcon {
			width: 28rpx;
			height: 28rpx;
		}

		.title {
			font-weight: 700;
			font-size: 26rpx;
			color: #121212;
			letter-spacing: 5rpx;
		}

		.notBlock {
			width: 17rpx;
			height: 17rpx;
			background: #f0f0f0;
			margin-left: 265rpx;
		}

		.notLabel {
			font-weight: 500;
			font-size: 20rpx;
			color: #8E8E8E;
			margin-left: 14rpx;
		}

		.canBox {
			display: flex;
			align-items: center;
			margin-left: auto;

			.canBlock {
				width: 17rpx;
				height: 17rpx;
				background: #FF6E5D;
			}

			.canLabel {
				font-weight: 500;
				font-size: 20rpx;
				color: #121212;
				margin-left: 14rpx;
			}
		}

	}

	::v-deep .uni-select {
		border: none;
	}

	::v-deep .uni-select .uni-icons {
	  display: none;
	}

	::v-deep .uni-select__input-box {
		opacity: 0 !important;
	}

	.selectetime {
		position: absolute;
		right: 0rpx;
		width: 200rpx;
		height: 100%;
	}

	.line1 {
		width: 4rpx;
		height: 20rpx;
		background: #ff6d5c;
		position: absolute;
		left: 0;
	}

	.content {
		width: 100%;
		min-height: 100vh;
		/* 允许内容扩展 */
		background-color: #f0f0f0;
		padding-bottom: 200rpx;
	}
</style>